﻿using System;
using Microsoft.EntityFrameworkCore;
using NewsPublish.Model.Entity;

namespace JT.WEB.Service
{
    //数据访问上一下文
    public class ContextNews : DbContext
    {
        public ContextNews()
        {

        }
        //protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        //{
        //    base.OnConfiguring(optionsBuilder);
        //    optionsBuilder.UseSqlServer("Data Source=LAPTOP-V4CIVOJN;Initial Catalog=JTWEB3;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", b=>b.UseRowNumberForPaging());
        //}
        public ContextNews(DbContextOptions<ContextNews> options) : base(options) { }

        public virtual DbSet<Banner> Banner { get; set; }
        public virtual DbSet<News> News { get; set; }
        public virtual DbSet<NewsClassify> NewsClassify { get; set; }
        public virtual DbSet<NewsComment> NewsComment { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<NewsClassify>().HasData(

                new NewsClassify { Id = 1, Name = "公司动态", Remark = "公司动态", Sort = 1 },
                new NewsClassify { Id = 2, Name = "行业动态", Remark = "行业动态", Sort = 2 }
            );

            modelBuilder.Entity<News>().HasData(
                new News { Id = 1, Contents = "网站开始运行！", ContentsHtml = "<p>网站开始运行</p>", NewsClassifyId = 1, PublishDate = DateTime.Now, Title = "网站开始运行！", Remark = "网站开始运行！", Image = "/NewsPic/20190930121913.jpg" }
            );
        }
    }
}